import request from "@/utils/request";
import { ProjectLockLogEditForm, ProjectLockLogQuery, AuditForm } from "./types";

/**
 * 获取项目解上锁记录列表复核列表
 * @param data
 */
export function QueryProjectLockLogFH(data: ProjectLockLogQuery) {
  let url = "/api/v1/sysuser/projectLockLog/page_fh";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/page_fh";
      break;
    case "Corp":
      url = "/api/v1/corp/projectLockLog/page_fh";
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/page_fh";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取项目解上锁记录列表复核选择上锁的记录
 * @param data
 */
export function QueryProjectLockLogPD(data: ProjectLockLogQuery) {
  let url = "/api/v1/sysuser/projectLockLog/page_pull_down";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/page_pull_down";
      break;
    case "Corp":
      url = "/api/v1/corp/projectLockLog/page_pull_down";
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/page_pull_down";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取项目解上锁记录列表
 * @param data
 */
export function QueryProjectLockLog(data: ProjectLockLogQuery) {
  let url = "/api/v1/sysuser/projectLockLog/page";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/page";
      break;
    case "Corp":
      url = "/api/v1/corp/projectLockLog/page";
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/page";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 历史状态复核申请
 * @param data
 */
export function CreateProjectLockLog(data: ProjectLockLogEditForm) {
  let url = "/api/v1/sysuser/projectLockLog/";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/";
      break;
    case "Corp":
      url = "/api/v1/corp/projectLockLog/";
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/";
  }
  return request({
    url: url + data.id,
    method: "put",
    data: data,
  });
}

/**
 * 历史状态复核申请
 * @param data
 */
export function AuditProjectLockLog(data: AuditForm) {
  let url = "/api/v1/sysuser/projectLockLog/audit/";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/audit/";
      break;
    case "Corp":
      url = "/api/v1/corp/projectLockLog/audit/";
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/audit/";
  }
  return request({
    url: url + data.id,
    method: "put",
    data: data,
  });
}

/**
 * 获取项目解上锁表单信息
 */
export function GetProjectLockLog(id: number) {
  let url = "/api/v1/sysuser/projectLockLog/";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = `/api/v1/manager/projectLockLog/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockLog/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/projectLockLog/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 删除项目解上锁表单信息
 */
export function DeleteProjectLockLog(id: number) {
  return request({
    url: `/api/v1/sysuser/projectLockLog/${id}`,
    method: "delete",
  });
}

/**
 * 获取项目解上锁表单信息
 */
export function GetProjectLockLogDetail(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectLockLog/detail/" + id;
      break;
    case "Corp":
      url = "/api/v1/manager/projectLockLog/detail/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectLockLog/detail/" + id;
      break;
    default:
      url = "/api/v1/sysuser/projectLockLog/detail/" + id;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 手动推送解上锁记录
 */
export function PushProjectLockLog(code: string) {
  let url = `/api/v1/cmssupportApi/projectLock/${code}`;

  return request({
    url: url,
    method: "post",
  });
}
